home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / amos / AMOS0398.lzh / AMOSLIST / 000299_amos-request@svcs1.digex.net_Fri Mar 27 19:35:21 1998.msg < prev    next >
Text File  |  1998-04-01  |  5KB  |  136 lines

  1. >From amos-request@svcs1.digex.net  Fri Mar 27 19:35:21 1998
  2. Received: from svcs1.digex.net (svcs1.digex.net [204.91.197.224])
  3.     by pony-1.mail.digex.net (8.8.8/8.8.8) with ESMTP id TAA02632
  4.     for <mcox@access.digex.net>; Fri, 27 Mar 1998 19:35:21 -0500 (EDT)
  5. Received: (from daemon@localhost)
  6.     by svcs1.digex.net (8.8.5/8.8.5) id PAA04800
  7.     for amos-out; Fri, 27 Mar 1998 15:57:37 -0500 (EST)
  8. Received: from pony-1.mail.digex.net (pony-1.mail.digex.net [204.91.241.5])
  9.     by svcs1.digex.net (8.8.5/8.8.5) with ESMTP id PAA04791
  10.     for <amos-list@svcs1.digex.net>; Fri, 27 Mar 1998 15:57:35 -0500 (EST)
  11. Received: from mail-in1.inet.tele.dk (mail-in1.inet.tele.dk [194.182.148.158])
  12.     by pony-1.mail.digex.net (8.8.8/8.8.8) with SMTP id PAA10919
  13.     for <amos-list@access.digex.net>; Fri, 27 Mar 1998 15:57:34 -0500 (EST)
  14. Received: (qmail 23816 invoked from network); 27 Mar 1998 20:57:31 -0000
  15. Received: from post10.tele.dk (194.239.134.174)
  16.   by mail-in1.inet.tele.dk with SMTP; 27 Mar 1998 20:57:31 -0000
  17. Received: from post10.tele.dk ([194.239.152.57]) by post10.tele.dk
  18.           (Netscape Mail Server v2.02) with SMTP id AAA9610;
  19.           Fri, 27 Mar 1998 21:57:28 +0100
  20. From: Rune Zedeler <rzedeler@post10.tele.dk>
  21. To: Declan_Gorman@modusmedia.com
  22. CC: AMOS List <amos-list@access.digex.net>
  23. Date: Fri, 27 Mar 1998 20:50:43 +0100
  24. Message-ID: <yam7390.2189.139021968@post10.tele.dk>
  25. In-Reply-To: <00019BD3.eval@modusmedia.com>
  26. X-Mailer: YAM 1.3.5 [040] - Amiga Mailer by Marcel Beck
  27. Subject: Re: Sorting Problem
  28. MIME-Version: 1.0
  29. Content-Type: text/plain; charset=iso-8859-1
  30. Content-Transfer-Encoding: 8bit
  31. X-MIME-Autoconverted: from quoted-printable to 8bit by svcs1.digex.net id PAA04796
  32. Status: O
  33. X-Status: 
  34.  
  35. On 16-Mar-98, Declan_Gorman@modusmedia.com wrote:
  36.  
  37. >     My program has a memory bank which consists of 128 blocks of memory, 
  38. >     each 256k in size.  Each memory block has a name and category and I 
  39. >     want to be able to sort the bank by either.
  40.  
  41. This should do it:
  42.  
  43. <CUT>
  44.  
  45. ' Needs sorting string to be located in S_STR$(0) to S_STR$(NUM-1) 
  46. '   ( ... I don't know how to pass arrays to procs...) 
  47.  
  48. _SORT[128,256*1024,BANK_NUMBER,NUMBER_OF_ITEMS_IN_ARRAY,UNUSED_BANK]
  49.  
  50. Procedure _SORT[NUM,SIZ,BNK,ARR_SIZ,TMP_BNK]
  51.   Shared S_STR$()
  52.   
  53.   Reserve As Work TMP_BNK,SIZ
  54.   Dim CUR(NUM-1),OLD(NUM-1)
  55.   
  56.   'Add number of item to the end of the string 
  57.   For I=0 To NUM-1 : S_STR$(I)=S_STR$(I)+Hex$(I,4) : Next I
  58.   'ensure that unused items in array will be placed first after sorting
  59.   If ARR_SIZ>NUM
  60.     For I=NUM To ARR_SIZ-1 : S_STR$(I)='' : Next I
  61.   End If 
  62.   Sort S_STR$(0)
  63.   'move sorted items FROM last TO first in array 
  64.   For I=0 To NUM-1 : S_STR$(I)=S_STR$(I+ARR_SIZ-NUM) : Next I
  65.   
  66.   'At this point the first NUM indexes in S_STR$() contains sorted 
  67.   'data - followed by the original position in the array.
  68.   
  69.   For I=0 To NUM-1 : CUR(I)=I : OLD(I)=I : Next I
  70.   'CUR(ORIGINAL_POS) contains CURRENT_POS  
  71.   'OLD(CURRENT_POS) contains ORIGINAL_POS
  72.   
  73.   For I=0 To NUM-1
  74.     'OLDI=what index index I had before sorting. 
  75.     OLDI=Val(Right$(S_STR$(I),5))
  76.     'J=Current position of block 
  77.     J=CUR(OLDI)
  78.     Print OLDI,J
  79.     S_STR$(I)=Left$(S_STR$(I),Len(S_STR$(I))-5)
  80.     'swap blocks:
  81.     If I<>J
  82.       Copy Start(BNK)+I*SIZ,Start(BNK)+(I+1)*SIZ To Start(TMP_BNK)
  83.       Copy Start(BNK)+J*SIZ,Start(BNK)+(J+1)*SIZ To Start(BNK)+I*SIZ
  84.       Copy Start(TMP_BNK),Start(TMP_BNK)+SIZ To Start(BNK)+J*SIZ
  85.       Swap CUR(OLD(I)),CUR(OLD(J))
  86.       Swap OLD(I),OLD(J)
  87.     End If 
  88.   Next I
  89.   Erase TMP_BNK
  90. End Proc
  91.  
  92. <CUT>
  93.  
  94. Quick tech explanation (hmmm, how it works, eh):
  95. I use the internal AMOS sort cmd. But before sorting I add the hex number to
  96. the end of the strings. So if the strings are:
  97.  
  98. Hi
  99. There
  100. !!!
  101.  
  102. then I add like this:
  103.  
  104. Hi$0000
  105. There$0001
  106. !!!$0002
  107.  
  108. After sorting (using "Sort") it is:
  109.  
  110. !!!$0002
  111. Hi$0000
  112. There$0001
  113.  
  114. - and I can use the numbers to move around in the bank.
  115.  
  116. I reserve a temp bank on the size of one block (that is 256k)
  117.  
  118. As I do not have 32MB of ram I have not been able to test it with your amount
  119. of memory. It moves the memory three times. That is: It will move 96MB of
  120. data! So it'll probably use a small amount of time.
  121.  
  122. Just write a letter to the list (send a copy to me personally, as I am only
  123. very seldom at home and therefore incidentally skips some letters in the
  124. mailinglists) if you have questions.
  125.  
  126. -- 
  127.  
  128.          /�\ __    __ /�����\           _         Rune Zedeler
  129. ________/ /// \\__/ \\\  ---/           \�-_      Peter R�rdams Vej 19
  130. \      / //�|  \\/  ||�\ \\��������������   ï¿½-_   2800 Lyngby
  131.  )    / //  | \ ` / ||  \ \\ Lemmus of Efreet  -  Denmark
  132. /    / ï¿½ï¿½ï¿½ï¿½ï¿½\\|\-'/ /����� \\____________   _-�
  133. �����\------'/||��| \------'/           /_-�      rzedeler@post10.tele.dk
  134.       ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½\-'/  \-'/������            ï¿½         Tel: +45-45871730
  135.              ï¿½ï¿½    ï¿½ï¿½
  136.